
public class Planet implements Comparable<Planet> {
	
	public String name;
	public int population;
	public int klingonWarbirds;
	public double distance;
	public boolean inhabitable;
	
	public Planet(String name, int population, int klingonWarbirds,	double distance, boolean inhabitable) {
		this.name = name;
		this.population = population;
		this.klingonWarbirds = klingonWarbirds;
		this.distance = distance;
		this.inhabitable = inhabitable;
	}

	public int compareTo(Planet planet) {
		//Since integer cannot represent more than 10 digits, 
		//long primitive data type is used.
		long rank = (long) (Math.max((1/(population
				+ 1000000*klingonWarbirds
				- distance/10000000000L
				+ 1000000000*(inhabitable? 1:(-1)))),0));
		long pRank = (long) (Math.max((1/(planet.population
				+ 1000000*planet.klingonWarbirds
				- planet.distance/10000000000L
				+ 1000000000*(planet.inhabitable? 1:(-1)))),0));
		
		if(rank-pRank < 0){
			return -1;
		}
		else if(rank-pRank >0){
			return 1;
		}
		else{
			return 0;
		}
	}
}
